#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;

signed main() {
	IOS;
	int t;
	cin >> t;
	while(t -- ) {
		int n, q;
		cin >> n >> q;
		int a[n + 10];
		map<int, int>cnt;
		set<int>se;
		int ma = 0;
		
		for(int i = 1; i <= n; i ++ ) {
			cin >> a[i];
			cnt[a[i]] ++ ;
			ma = max(ma, cnt[a[i]]);
			se.insert(a[i]);
		}
		int sum[ma + 10];
		memset(sum, 0, sizeof sum);
		for(int i : se) {
			sum[cnt[i]] += cnt[i];
		}
		sum[0] = 0;
		for(int i = 1; i <= ma; i ++ ) {
			sum[i] += sum[i - 1];  
			//cout << "i = " << i << " " << sum[i] << endl;
		}
		while(q -- ) {
			int x;
			cin >> x;
			if(x > ma) {
				cout << 0 << " ";
			} else {
				cout << sum[ma] - sum[x] << " ";
			}
		}
		cout << endl;
	} 
	return 0;
}
